<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>添加人员</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../common/mui/mui.css" rel="stylesheet" />
		<link href="../../common/css/yahei.css" rel="stylesheet" />
		<link href="../../common/css/iconfont.css" rel="stylesheet" />
		<link href="../../common/css/app.css" rel="stylesheet" />
		<!-- <link href="../dependence/teach/css/teachPublic.css" rel="stylesheet" /> -->
		<link href="../../dependence/wkplatform/css/ky/kySelectPerson.css" rel="stylesheet" />
		<style type="text/css">
			.searchArea{
				background-color: white;
			}
			#wrapper{
				top: calc(var(--size60) + 44px);
				bottom: var(--size50);
				background-color: white;
				font-size: var(--size14);
			}
			
			.nullData{
				margin-top: var(--size60);
				display: none;
			}
			.bottomArea{
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				height: var(--size50);
				background-color: white;
				display: flex;
			}
			.cancelBtn,.sureBtn{
				width: 50%;
				height: 100%;
				font-size: var(--size14);
				color: white;
				background-color: var(--mainColor);
				line-height: var(--size50);
				text-align: center;
			}
			.cancelBtn{
				color: var(--mainColor);
				background-color: white;
			}
		</style>
	</head>

	<body class="YaHei">
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">添加人员</h1>
		</header>
		<div class="mui-content">
			<div class="searchArea">
				<div class="mui-input-row mui-search">
					<input id="search" type="search" class="mui-input-clear" placeholder="搜索人员"/>
				</div>
			</div>
			<div id="wrapper" class="mui-scroll-wrapper">
				<div class="mui-scroll mui-scroll-phone">
					<ul id="UL" class="mui-table-view"></ul>
				</div>
			</div>
			<div id="nullData" class="nullData">
				<div class="nullImage"></div>
				<div id="nullTip" class="nullTip">暂无内容</div>
			</div>
			<div class="bottomArea">
				<div class="cancelBtn">取消</div>
				<div class="sureBtn">确定</div>
			</div>
		</div>
		
		<script src="../../common/mui/mui.js"></script>
		<script src="../../common/mui/mui.pullToRefresh.js"></script>
		<script src="../../common/mui/mui.pullToRefresh.material.js"></script>
		<script src="../../common/js/jquery-3.4.1.min.js"></script>
		<script src="../../common/js/globalSet.js"></script>
		<script src="../../common/js/DHCWebService.js"></script>
		<script type="text/javascript">
	var nurseid='',start=0,limit=2000,sourceData;
	mui.init();
	mui.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	function addPerson(argInfo,locSchArr,tempIndex){
		if (locSchArr !="") {
			sourceData['locSchArr'] = locSchArr
			sourceData['argInfo'] = argInfo
			sourceData['rw'] = argInfo['rw']
		}
		var persons = ''
		mui('#UL .dhc-active').each(function (index,element) {
			if (index > 0) {
				persons += ','
			}
			persons += element.getAttribute('data-PerID')
		})
		if (persons == '') {
			mui.toast('请选择要添加的人员')
			return
		}
		//ArgWardDR|病区Id^ArgStDate|开始日期^ArgEndDate|结束日期^ArgCrtUser|创建者user Id^ArgRemarks|排班表备注^ArgStatus|状态^rw|排班表Id^WardDesc|病区描述
		var pdict = {'parr1':sourceData['parr1'],'persons':''}
		var paramDict = {'method':'web.INMArgComm:AddArgPersons','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msg'] == '0') {
				mui.toast('添加失败')
				return
			}
			mui.toast('添加成功');
			mui.back()
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	function getPersonAddList(){
		//病区Id^开始日期^结束日期^人员类型  
		//人员类型：正式（N）、进修（S）、实习（P）、护理员（W） 管理员（M） 工人（G）） 助理护士（A） 护理学员（T）  用户(U)
		var pdict = {'parr':sourceData.wardID+'^'+sourceData.startDate+'^'+sourceData.endDate+'^'}
		var paramDict = {'method':'web.INMHRComm:GetLocNurList','params':JSON.stringify(pdict),'type':'MethodNoFilter'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msgcode'] != '1') {
				mui('#tbody')[0].innerHTML = ''
				showNullTip(result['msg'])
				return
			}
			hideNullTip()
			updatePersonUI(result['data'])
		}, function(errorStr) {
			mui('#tbody')[0].innerHTML = ''
			showNullTip(errorStr,'error')
		});
	}
	/*"IsHead":"true","PerDR":"676","PerID":"4095","PerName":"张璐诗","Selectable":"true","WardDesc":"内分泌科护理单元"*/
	function updatePersonUI(dataArr){
		var html = '';
		for (var i = 0; i < dataArr.length; i++) {
			var oneWard = dataArr[i]['Nurse']
			var wardDesc = dataArr[i]['WardDesc']
			var wardHtml = ''
			var count = 0
			for (var j = 0; j < oneWard.length; j++) {
				var oneData = oneWard[j]
				if (oneData['Selectable'] != 'true') {
					continue
				}
				count +=1
				wardHtml += '<li class="mui-table-view-cell person" data-PerID="'+oneData['PerID']+'">'+
					'<div class="square"></div>'+
					'<div class="nurName mui-ellipsis">'+oneData['PerName']+'</div>';
				if (oneData['IsHead'] == 'true') {
					wardHtml += '<div class="nurHead">护士长</div>'
				}
				wardHtml +='</li>'
			}
			if (wardHtml != '') {
				html += '<li class="mui-table-view-cell">'+wardDesc+'（'+count+'人）'+'</li>'+wardHtml	
			}
		}
		
		mui('#UL')[0].innerHTML = html
		if (html == '') {
			showNullTip('暂无可选人员');
		}
	}
	
	function baseSetup(){
		mui('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		mui('#UL').on('tap','.person',function(){
			this.classList.add('dhc-active')
		})
		mui('.bottomArea').on('tap','.cancelBtn',function(){
			mui('#UL .dhc-active').each(function (index,element) {
				element.classList.remove('dhc-active')
			})
		}) 
		mui('.bottomArea').on('tap','.sureBtn',function(){
			if (sourceData['rw'] != "") {
				addPerson(sourceData.argInfo,"","")
				return
			}
			var schLocPage = plus.webview.getWebviewById('nurSchLoc')
			if (schLocPage) {
				schLocPage.evalJS('refreshPageData("create","nurSchPerSet","addPerson")')
			}
		}) 
		var self = plus.webview.currentWebview();
		sourceData = self.sourceData
		nurseid = sourceData.nurseid
		getPersonAddList();
	}

	function showNullTip(msg,type){
		mui('#nullData')[0].style.display = 'block';
		mui('#nullTip')[0].innerHTML = msg
	}
	function hideNullTip(){
		mui('#nullData')[0].style.display = 'none';
	}
		</script>
	</body> 

</html>
